<?php

/**
 * CCoreMimeMessageAttachment
 * CCoreMimeMessageAttachmentsCollection
 *
 * @author Usenko Timur <usenko.timur@gmail.com>
 * @package mime
 */

CCore::Using('base.collection');
CCore::Using('mime.part');

/**
 * @package mime
 */
class CCoreMimeMessageBodyText
{
	/**
	 * @var CCoreMimePart
	 */
	private $_oMimePart;

	/**
	 * @var bool
	 */
	private $_bIsHtml;

	/**
	 * @param CCoreMimePart $oMimePart
	 * @return CCoreMimeMessageBodyText
	 */
	public function __construct(CCoreMimePart &$oMimePart)
	{
		$this->_oMimePart =& $oMimePart;

		$sContentTypeFirstParamValue =
			strtolower($oMimePart->Headers->GetValueByName(C_MIME_HEADERS_CONTENT_TYPE));

		$this->_bIsHtml = (false !== strpos($sContentTypeFirstParamValue, 'text/html'));
	}

	/**
	 * @return bool
	 */
	public function IsHtml()
	{
		return $this->_bIsHtml;
	}

	/**
	 * @return resourse
	 */
	public function GetBodyStream()
	{
		return $this->_oMimePart->Body;
	}

	/**
	 * @return resourse
	 */
	public function GetBinaryBodyStream()
	{
		return $this->_oMimePart->GetBinaryBodyStream();
	}
}

/**
 * @package mime
 */
class CCoreMimeMessageBodyTextCollection extends ACoreBaseCollection
{
	/**
	 * @return CCoreMimeMessageBodyTextCollection
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * @param CCoreMimeMessageBodyText $oMimeMessageBodyText
	 * @return void
	 */
	public function Add(CCoreMimeMessageBodyText $oMimeMessageBodyText)
	{
		CCore::CheckTypes(array('$oMimeMessageBodyText'));

		parent::Add($oMimeMessageBodyText);
	}
}